<?php

namespace App\Providers;

use App\Auth\BackendGuard;
use App\Auth\BackendUserProvider;
use App\Auth\MpGuard;
use App\Auth\MpUserProvider;
use App\Auth\SchoolGuard;
use App\Auth\SchoolUserProvider;
use Illuminate\Hashing\BcryptHasher;
use Illuminate\Support\Facades\Auth;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;

class AuthServiceProvider extends ServiceProvider
{
    /**
     * The policy mappings for the application.
     *
     * @var array
     */
    protected $policies = [
        'App\Model' => 'App\Policies\ModelPolicy',
    ];

    /**
     * Register any authentication / authorization services.
     *
     * @return void
     */
    public function boot()
    {
        $this->registerPolicies();
        Auth::extend('backend',function ($app, $name, array $config){
            return new BackendGuard(Auth::createUserProvider($config['provider']),request());
        });
        Auth::provider('backend',function ($app, array $config){
            return new BackendUserProvider(new BcryptHasher(),$config['model']);
        });
        Auth::extend('school',function ($app, $name, array $config){
            return new SchoolGuard(Auth::createUserProvider($config['provider']),request());
        });
        Auth::provider('school',function ($app, array $config){
            return new SchoolUserProvider(new BcryptHasher(),$config['model']);
        });
        Auth::extend('mp',function ($app, $name, array $config){
            return new MpGuard(Auth::createUserProvider($config['provider']),request());
        });
        Auth::provider('mp',function ($app, array $config){
            return new MpUserProvider(new BcryptHasher(),$config['model']);
        });
    }
}
